import React from 'react'
import { connect } from 'dva'
import { Form ,Button,Modal,Popconfirm,Table,Row,Col,Input,Select,Cascader,Icon,Checkbox ,DatePicker} from 'antd'
import { Link, hashHistory } from 'dva/router'
import config from 'config/config'
import { mapStateToProps } from 'utils/view_utils'
import styles from './commissionPaymentListStyle.less'
import ListPage from 'widget/PageTmpl/ListPage'
import classnames from 'classnames/bind';
let cx=classnames.bind(styles);
import { CustomCard} from '../../../widget/Grid/CustomCard'
import FlagBtn from 'widget/FlagBtn/FlagView'
const confirm = Modal.confirm;

const commissionPaymentListView = function({dispatch, model, form}) {
  // 表单的子函数
  const {resetFields, getFieldDecorator, validateFields, setFieldsValue} = form
  // 取出model对象，命名空间
  const { modelObj, namespace } = model
  // modelObj.xxx获取model中状态机的值
  let { areaList,area1,biz,products } = modelObj

  // let option = [
  //   { value: 'success', label: '处理成功' },
  //   { value: 'fail', label: '处理失败' },
  //   { value: 'processing', label: '处理中' },
  // ]
  // function centCommission(options){
  //   console.log(options)
  //   dispatch({
  //     type:`${namespace}/centCommission`,
  //     payload:{id:options}
  //   })
  // }

  const down = ()=>{
    dispatch({
      type:`${namespace}/down`,
      payload: {}
    })
  }
 
  let pageProps = {
    // ---------- 界面部分 ----------
    ui: {
      // 页面接口地址
      api_url: `3rd/commission/selectPayDetail`,
      //api_url: `admin/news/list`,
      // 接口方式
      method: "POST",
      // "data_field_name":"data",
      app: "",
      // 接口参数
      params: {
        // type:2
      },
      // 模拟数据 - 用于开发需要，若填充了上面的api_url之后，请将此项设置为null
      // "mockData": mockData,
      mockData: null,
      // 查询栏
      search_bar: {
        fields: [
          {
            en_name: 'regionId',
            zh_name: '所属区域',
            elem_type: 'Select',
            elem_valid_type: 'string',
            	//关联的更改的搜索字段
            cmpt_items:area1,
         },
         {
          en_name: 'province',
          zh_name: '所属城市',
          elem_type: 'Cascader',
          elem_valid_type: 'string',
          changeOnSelect:true,
          cmpt_items: areaList,
          split_keys: ['provinceCode', 'cityCode'],
          onFocus:()=>{
            area1.map((item,index)=>{
              // console.log(biz.queryForm.regionId,item.value)
              if(biz.queryForm && biz.queryForm.regionId && biz.queryForm.regionId==item.value)
              {
                // console.log(biz.queryForm.regionId,item.value)
                dispatch({
                  type: `${namespace}/updateStore`,
                  payload:{
                    areaList:item.children,
                  }
                })
              }
            })
          },
        },
        {
          en_name: 'projectId',
          zh_name: '项目名称',
          elem_type: 'Select',
          elem_valid_type: 'string',
          // showSearch:true,
          cmpt_items:products,
          onFocus:()=>{
            if(biz.queryForm && biz.queryForm.cityCode && biz.queryForm.cityCode)
            {
              dispatch({
                type: `${namespace}/getProduct`,
                payload:{
                  cityCode:biz.queryForm.cityCode,
                }
              })
            }
          },
        },
          // {
          //   en_name: 'projectName',
          //   zh_name: '项目名称',
          //   elem_type: 'Input',
          //   elem_valid_type: 'string',
          // },
          // {
          //   en_name: 'partnershipMobile',
          //   zh_name: '经纪人手机号',
          //   elem_type: 'Input',
          //   elem_valid_type: 'string',
          // },
          {
            en_name: 'vbillno',
            zh_name: '佣金申请单',
            elem_type: 'Input',
            elem_valid_type: 'string',
          },
          // {
          //   en_name: 'payStatus',
          //   zh_name: '分账状态',
          //   elem_type: 'Select',
          //   cmpt_items: option,
          //   elem_valid_type: 'string',
          // },
          {
            en_name: 'validTime',
            zh_name: '付款时间',
            elem_type: 'Date',
            format: 'YYYY-MM-DD',
            // query_format: "YYYY-MM-DD HH:mm:ss",   // 请求参数, 当请求参数和显示时格式不同可通过该参数区分
            // double: true,  // 日期范围组件 使用"YYYY-MM-DD HH:mm:ss"格式时, 显示不全时可使用该参数, 将占据两格位置
            split_keys: ['paytimeStart', 'paytimeEnd'],
            elem_valid_type: 'string'
          },
        ],
        searchHandler: () => { // 自定义搜索按钮回调函数，点击搜索时触发
          console.log('search click')
        },
        resetHandler: () => { // 自定义重置按钮回调函数，点击重置时触发
          console.log('reset click')
        },
        searchCallback: params => { // 自定义搜索完成后的后调函数, 搜索完成后触发, 并将本次搜索的参数传入
          console.log('search finish', params)
        },
        pasteTargetList: [  // 列表组件中将输入框的en_name作为默认id(也可以通过id另外设置)
          'channel',  // 将需要粘贴事件拦截的输入框id以数组的形式传入, 该参数对应PasteFromClipboard组件的targetList参数
        ]
      },
      // 数据表格  序号 资讯标题 所属项目  所属城市 创建人 创建时间 更新人 更新时间   操作
      table:
        {
          status_params: "status=0",
          status_text: "全部",
          // 表头字段列表
          scroll: { x: 1800},
          fields: [
            {
              en_name: "vbillno",
              zh_name: "佣金申请单号",
              width:150,
              fixed: 'left',
            },
            {
              en_name: "projectName",
              zh_name: "项目名称",
            },
            {
              en_name: "summoneySh",
              zh_name: "佣金金额",
            },
            {
              en_name: "paybillno",
              zh_name: "资金付款单号",
            },
            {
              en_name: "paytime",
              zh_name: "资金付款时间",
            },
            {
              en_name: "fkbillno",
              zh_name: "付款申请单单号",
            },
            {
              en_name: "fkbilldate",
              zh_name: "付款单单据日期",
            },
            {
              en_name: "venderName",
              zh_name: "分佣账户",
            },
            {
              en_name: "countTotal",
              zh_name: "结佣人员数量",
            },
            {
              en_name: "countSuccess",
              zh_name: "分账成功数量",
            },
            {
              en_name: "countFail",
              zh_name: "分账失败数量",
            },
            // {
            //   en_name: "edit",
            //   zh_name: "操作",
            //   width:50,
            //   fixed:'right',
            //   render: (a, item, index, d, e, f) => {
            //     return (
            //       <span>
            //         {item.c3Vbillstatus == '流程通过' && item.zjVbillstatus == 'paysuccess' && (item.payStatus == null || item.payStatus == '' ||item.payStatus=='fail')?
            //         <FlagBtn
            //             node={<Popconfirm  Collapse title='确定要分佣吗？' okText='确定' cancelText='取消' onConfirm={() => { centCommission(item.id,item.c3Vbillstatus,item.zjVbillstatus) }}>
            //               <a >分佣</a>
            //             </Popconfirm>}
            //             btnId={''}>
            //         </FlagBtn>:<span style={{color:'#999'}}>分佣</span>
            //         }
            //          {/* {item.payStatus !='processing' ||item.payStatus !='success'?
            //          } */}
            //         </span>
            //     )
            //   },
            // }
          ]
        },
      // 操作栏
      action_bar: [
        {
          label:'导出',
          btnId:'70202',
          type:'primary',
          onClick:(e,row)=>{
              down()
          }
        },
      ]
    },
  }
  
  if (!!modelObj.biz) {
		pageProps.biz = modelObj.biz
		pageProps.biz.syncBackCbf = (biz) => {
			dispatch({
				type: `${namespace}/updateStore`,
				payload: { biz }
			})
		}
  }
  
  return (
    <div className={cx('pageLayout')}>
      <ListPage pageProps={pageProps}/>
    </div>
  )
}
// 连接视图(view)和模型(model)
export default connect(mapStateToProps)(Form.create()(commissionPaymentListView))
